home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / _editutils.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  8KB  |  202 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk, GObject
  5. from quodlibet import config
  6. from quodlibet import util
  7. from quodlibet.plugins import PluginHandler
  8. from quodlibet.qltk.ccb import ConfigCheckButton
  9. from quodlibet.qltk.msg import WarningMessage, ErrorMessage
  10. from quodlibet.qltk.x import Button
  11. from quodlibet.util.path import fsdecode
  12. from quodlibet.util import connect_obj
  13.  
  14. class OverwriteWarning(WarningMessage):
  15.     RESPONSE_SAVE = 1
  16.     
  17.     def __init__(self, parent, song):
  18.         title = _('Tag may not be accurate')
  19.         fn_format = '<b>%s</b>' % util.escape(fsdecode(song('~basename')))
  20.         description = _('%(file-name)s changed while the program was running. Saving without refreshing your library may overwrite other changes to the song.') % {
  21.             'file-name': fn_format }
  22.         super(OverwriteWarning, self).__init__(parent, title, description, buttons = Gtk.ButtonsType.NONE)
  23.         self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
  24.         save_button = Button(_('_Save'), 'document-save')
  25.         save_button.show()
  26.         self.add_action_widget(save_button, self.RESPONSE_SAVE)
  27.         self.set_default_response(Gtk.ResponseType.CANCEL)
  28.  
  29.  
  30.  
  31. class WriteFailedError(ErrorMessage):
  32.     
  33.     def __init__(self, parent, song):
  34.         title = _('Unable to save song')
  35.         fn_format = '<b>%s</b>' % util.escape(fsdecode(song('~basename')))
  36.         description = _('Saving %(file-name)s failed. The file may be read-only, corrupted, or you do not have permission to edit it.') % {
  37.             'file-name': fn_format }
  38.         super(WriteFailedError, self).__init__(parent, title, description)
  39.  
  40.  
  41.  
  42. class EditingPluginHandler(GObject.GObject, PluginHandler):
  43.     __gsignals__ = {
  44.         'changed': (GObject.SignalFlags.RUN_LAST, None, ()) }
  45.     Kind = None
  46.     
  47.     def __init__(self):
  48.         super(EditingPluginHandler, self).__init__()
  49.         self._EditingPluginHandler__plugins = []
  50.  
  51.     
  52.     def plugins(self):
  53.         return list(self._EditingPluginHandler__plugins)
  54.  
  55.     plugins = property(plugins)
  56.     
  57.     def plugin_handle(self, plugin):
  58.         return issubclass(plugin.cls, self.Kind)
  59.  
  60.     
  61.     def plugin_enable(self, plugin):
  62.         self._EditingPluginHandler__plugins.append(plugin.cls)
  63.         self.changed()
  64.  
  65.     
  66.     def plugin_disable(self, plugin):
  67.         self._EditingPluginHandler__plugins.remove(plugin.cls)
  68.         self.changed()
  69.  
  70.     
  71.     def changed(self):
  72.         self.emit('changed')
  73.  
  74.  
  75.  
  76. class FilterCheckButton(ConfigCheckButton):
  77.     __gsignals__ = {
  78.         'preview': (GObject.SignalFlags.RUN_LAST, None, ()) }
  79.     
  80.     def __init__(self):
  81.         super(FilterCheckButton, self).__init__(self._label, self._section, self._key)
  82.         
  83.         try:
  84.             self.set_active(config.getboolean(self._section, self._key))
  85.         except:
  86.             pass
  87.  
  88.         connect_obj(self, 'toggled', self.emit, 'preview')
  89.  
  90.     active = property((lambda s: s.get_active()))
  91.     
  92.     def filter(self, original, filename):
  93.         raise NotImplementedError
  94.  
  95.     
  96.     def filter_list(self, origs, names):
  97.         return map(self.filter, origs, names)
  98.  
  99.     
  100.     def __lt__(self, other):
  101.         return (self._order, type(self).__name__) < (other._order, type(other).__name__)
  102.  
  103.  
  104.  
  105. class FilterPluginBox(Gtk.VBox):
  106.     __gsignals__ = {
  107.         'changed': (GObject.SignalFlags.RUN_LAST, None, ()),
  108.         'preview': (GObject.SignalFlags.RUN_LAST, None, ()) }
  109.     
  110.     def __init__(self, plugin_handler, filter_types = None):
  111.         super(FilterPluginBox, self).__init__()
  112.         if filter_types is None:
  113.             filter_types = []
  114.         filters = [ Kind() for Kind in filter_types ]
  115.         filters.sort()
  116.         for f in filters:
  117.             self.pack_start(f, True, True, 0)
  118.         
  119.         self._FilterPluginBox__filters = filters
  120.         self._FilterPluginBox__plugins = []
  121.         hb = Gtk.HBox()
  122.         expander = Gtk.Expander(label = _('_More options...'))
  123.         expander.set_use_underline(True)
  124.         hb.pack_start(expander, True, True, 0)
  125.         self.pack_start(hb, False, True, 0)
  126.         for filt in filters:
  127.             filt.connect(('preview',), (lambda : self.emit('preview')))
  128.         
  129.         sw = Gtk.ScrolledWindow()
  130.         sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
  131.         vbox = Gtk.VBox()
  132.         plugin_handler.connect('changed', self._FilterPluginBox__refresh_plugins, vbox, expander)
  133.         sw.add_with_viewport(vbox)
  134.         self.pack_start(sw, False, True, 0)
  135.         sw.set_no_show_all(True)
  136.         expander.connect('notify::expanded', self._FilterPluginBox__notify_expanded, sw)
  137.         expander.set_expanded(False)
  138.         for child in self.get_children():
  139.             child.show()
  140.         
  141.         plugin_handler.changed()
  142.         sw.hide()
  143.  
  144.     
  145.     def __notify_expanded(self, expander, event, vbox):
  146.         vbox.set_property('visible', expander.get_property('expanded'))
  147.  
  148.     
  149.     def __refresh_plugins(self, handler, vbox, expander):
  150.         instances = []
  151.         for Kind in handler.plugins:
  152.             
  153.             try:
  154.                 f = Kind()
  155.             except:
  156.                 util.print_exc()
  157.                 continue
  158.                 continue
  159.  
  160.             instances.append(f)
  161.         
  162.         instances.sort()
  163.         for child in vbox.get_children():
  164.             child.destroy()
  165.         
  166.         del self._FilterPluginBox__plugins[:]
  167.         for f in instances:
  168.             
  169.             try:
  170.                 vbox.pack_start(f, True, True, 0)
  171.             except:
  172.                 util.print_exc()
  173.                 f.destroy()
  174.                 continue
  175.  
  176.             
  177.             try:
  178.                 f.connect(('preview',), (lambda : self.emit('preview')))
  179.             except:
  180.                 
  181.                 try:
  182.                     f.connect(('changed',), (lambda : self.emit('changed')))
  183.                 util.print_exc()
  184.                 continue
  185.  
  186.  
  187.             self._FilterPluginBox__plugins.append(f)
  188.         
  189.         vbox.show_all()
  190.         if not self._FilterPluginBox__plugins:
  191.             expander.set_expanded(False)
  192.             expander.hide()
  193.         else:
  194.             expander.show()
  195.  
  196.     
  197.     def filters(self):
  198.         return self._FilterPluginBox__filters + self._FilterPluginBox__plugins
  199.  
  200.     filters = property(filters)
  201.  
  202.